import { usePopStore, useAirStore } from '@/stores'
import { airspaceMapServer, hangarDetailServer, getVideoServer } from '@/api'
import { addRiseLandPoint } from '@/views/infrastructure/js/infrastructure.js'
class MouseClick {
  async markerClick(data) {
    //关闭所有三维弹框
    const popStore = usePopStore()
    popStore.closeAllPop()

    if (data.Type === 'marker3d') {
      if (data.GroupID === 'spaceGrid-shifei' || data.GroupID === 'spaceGrid-guankong') {
        const res = await airspaceMapServer()
        const name = data.UserData
        setTimeout(() => {
          popStore.Airspace.showPop = true
        }, 2000)
        // popStore.Airspace.showPop = true
        popStore.Airspace.popInfo = res.data.filter((item) => item.airspaceName === name)[0]
        console.log(popStore.Airspace.popInfo, '-')
        if (popStore.Airspace.popInfo === undefined) {
          console.log('数据不存在', data.UserData)
          if (data.UserData === '盐田港区') {
            popStore.Airspace.popInfo = {
              airspaceArea: 11.63,
              airspaceName: '盐田港区',
              airspaceType: '管制空域',
              botHeight: 0,
              topHeight: 300
            }
          } else if (data.UserData === '盐田区政府') {
            popStore.Airspace.popInfo = {
              airspaceArea: 0.234,
              airspaceName: '盐田区政府',
              airspaceType: '管制空域',
              botHeight: 0,
              topHeight: 300
            }
          } else if (data.UserData === '沙头角口岸') {
            popStore.Airspace.popInfo = {
              airspaceArea: 0.06128,
              airspaceName: '沙头角口岸',
              airspaceType: '管制空域',
              botHeight: 0,
              topHeight: 300
            }
          } else if (data.UserData === '边防哨所') {
            popStore.Airspace.popInfo = {
              airspaceArea: 0.0439,
              airspaceName: '边防哨所',
              airspaceType: '管制空域',
              botHeight: 0,
              topHeight: 300
            }
          }
        }
        // __g.marker3d.focus(data.Id, 1200, [-21.246498, -122.79454, 0])
        if (data.Id === 'airspace-7') {
          __g.camera.set(530368.381719, 2493309.577422, 1963.000313, -15.219252, -131.615738, 2)
        } else if (data.Id === 'airspace-0') {
          __g.camera.set(536213.156875, 2495536.455625, 3255.905313, -22.659288, -127.645081, 2)
        } else if (data.Id === 'airspace-2') {
          __g.camera.set(530545.530625, 2498303.483125, 3245.290625, -19.144268, -124.394585, 2)
        } else if (data.Id === 'airspace-1') {
          __g.camera.set(532742.649687, 2492821.040625, 3037.764688, -19.669968, -129.26384, 2)
        } else if (data.Id === 'airspace-3') {
          __g.camera.set(528269.244219, 2496252.405781, 2548.930938, -22.345913, -132.101624, 2)
        } else if (data.Id === 'airspace-4') {
          __g.camera.set(527487.926055, 2492496.370703, 2637.055625, -20.365765, -129.461258, 2)
        } else if (data.Id === 'airspace-6') {
          __g.camera.set(524400.5925, 2493647.642344, 1949.687813, -14.703853, -133.395111, 2)
        } else if (data.Id === 'airspace-5') {
          __g.camera.set(525589.806875, 2494936.419688, 3401.830625, -32.261379, -125.522316, 2)
        } else if (data.Id === 'airspace-8') {
          __g.camera.set(526402.962656, 2493316.833906, 1676.116563, -14.506747, -131.312927, 2)
        } else if (data.Id === 'airspace-9') {
          __g.camera.set(525620.427188, 2492526.4225, 1676.116563, -14.506747, -131.312927, 2)
        } else if (data.Id === 'airspace-10') {
          __g.camera.set(534559.599375, 2498050.256875, 1393.599844, -14.506747, -131.312927, 2)
        }
        // else if (data.Id === 'airspace-7') {
        //     __g.camera.set(533905.396094, 2495770.120313, 2151.272969, -12.331967, -139.843765, 2)
        //   }
      }
    } else if (data.Type === 'marker') {
      //起降点
      if (data.GroupID === 'riseLand') {
        let userData = JSON.parse(data.UserData)
        popStore.RiseLand.popInfo = userData
        __g.marker.focus(data.Id, 20, 4) // 点击定位过去
        setTimeout(() => {
          // 过两秒再显示弹窗
          popStore.RiseLand.showPop = true
        }, 2000)
      }
      //通导监
      if (data.GroupID === 'equipment' || data.GroupID === 'equipmentxx') {
        let userData = JSON.parse(data.UserData)
        popStore.Equipment.showPop = true
        popStore.Equipment.popInfo = userData
      }
      //点击无人机
      if (data.GroupID === 'wrjMarker') {
        // return
        // const airStore = useAirStore()
        // // __g.customObject.focus(data.Id, -1)
        // __g.customObject.focus(data.Id, 100, 0, [-30, 4, 0], 1)
        // airStore.FocusAirId = data.Id.split('-')[1]
        // __g.marker.hideByGroupId('wrjMarker')
      }
      //通导监
      if (data.GroupID === 'jc') {
        let userData = JSON.parse(data.UserData)
        popStore.Jc.showPop = true
        popStore.Jc.popInfo = userData
        const res = await hangarDetailServer({ platformId: userData.platformId })
        // popStore.Jc.showPop = true
        // popStore.Jc.popInfo = res.data
        // const res02 = await getVideoServer({ id: userData.platformId })
      }

      // if (data.GroupID === 'RadarMarker') {
      //   let userData = JSON.parse(data.UserData)
      //   popStore.Radar.showPop = true
      //   popStore.Radar.popInfo = userData
      // }

      if (data.GroupID.includes('qxdev')) {
        //气象设备
        let userData = JSON.parse(data.UserData)
        popStore.Qx.showPop = true
        popStore.Qx.popInfo = userData
        __g.marker.focus(data.Id)
      }
    } else if (data.Type === 'CustomObj') {
      if (data.GroupID === 'wrjCustomObject') {
        const airStore = useAirStore()
        // __g.customObject.focus(data.Id, -1)
        __g.customObject.focus(data.Id, 100, 0, [-30, 4, 0], 1)
        airStore.FocusAirId = data.Id.split('-')[1]
        __g.marker.hideByGroupId('wrjMarker')
        // __g.marker.update({ id: data.Id, imageSize: [0,0]})
      }
    } else if (data.Type === '3dPolygon') {
      const ids = ['airspace-1', 'airspace-5', 'airspace-0', 'airspace-2']
      if (ids.includes(data.Id)) {
        __g.polygon3d.update({
          id: data.Id, //3DPolygon唯一标识id
          generateTop: false //是否生成顶面
        })
      }
    } else if (data.Type === 'Polyline') {
      if (data.Id.includes('hangxian')) {
        let userData = JSON.parse(data.UserData)
        popStore.Hangxian.showPop = true
        popStore.Hangxian.popInfo = userData
      }
    }
  }
}
export default MouseClick
